package com.bdqn.controller;

import com.bdqn.pojo.User;
import com.bdqn.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * <Description> <br>
 *
 * @author tao<br>
 * @version 1.0<br>
 * @taskId: <br>
 * @createDate 2019/10/15 8:55 <br>
 * @see com.bdqn.controller <br>
 */
@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping(value="/list",method = RequestMethod.GET)
    public String getUserList(Model model, HttpSession session){
        List<User> userList = userService.getAll();
        model.addAttribute("userList",userList);
        return "index";
    }

    /*
     * FreeMarker 快速入门 https://www.cnblogs.com/itdragon/p/7750903.html
     *
     * */
    @RequestMapping(value="/demo",method = RequestMethod.GET)
    public String test(Model model, HttpSession session){
        model.addAttribute("user","admin");
        model.addAttribute("num",100);
        model.addAttribute("date",new Date());
        return "demo";
    }

    /*页面静态化*/
    @GetMapping("/generate")
    public String generate(Model model, HttpSession session){
        return "generate";
    }

    /*页面静态化*/
    @GetMapping("/")
    public String staticPage(Model model, HttpSession session){
        return "/test.html";
    }

    @GetMapping("/freemarker")
    public String templates(Model model){
        model.addAttribute("w","哈哈囧");
        return "/staticPage";
    }
}
